home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Development Platforms / LISP Related / LISP Goodies / Wood / woodequ.lisp < prev   
Encoding:
Text File  |  1992-09-02  |  9.9 KB  |  318 lines  |  [TEXT/CCL2]

  1. ;;;-*- Mode: Lisp; Package: WOOD -*-
  2.  
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  4. ;;
  5. ;; woodequ.lisp
  6. ;; Data representation constants
  7. ;; Largely copied from "ccl:library;lispequ.lisp"
  8. ;;
  9. ;; Copyright © 1992 Apple Computer, Inc. All rights reserved.
  10. ;; Permission is given to use, copy, and modify this software provided
  11. ;; that this copyright notice is attached to all derivative works.
  12. ;; This software is provided "as is". Apple makes no warranty or
  13. ;; representation, either express or implied, with respect to this software,
  14. ;; its quality, accuracy, merchantability, or fitness for a particular
  15. ;; purpose.
  16. ;;
  17.  
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  19. ;;
  20. ;; Modification History
  21. ;;
  22. ;; -------------- 0.5
  23. ;; 06/23/92 bill  persistent-clos equates, btree type bits
  24. ;; -------------- 0.1
  25. ;;
  26.  
  27.  
  28. (in-package :wood)
  29.  
  30. ; low 3 bits of an address are the tag.
  31.  
  32. (defmacro pointer-tag (pointer)
  33.   `(the fixnum (logand ,pointer 7)))
  34.  
  35. (defmacro pointer-tagp (pointer tag)
  36.   `(eql (pointer-tag ,pointer) ,tag))
  37.             
  38. (defmacro pointer-address (pointer)
  39.   `(logand ,pointer -8))
  40.  
  41. (defconstant $t_fixnum 0)
  42. (defconstant $t_vector 1)
  43. (defconstant $t_symbol 2)
  44. (defconstant $t_dfloat 3)
  45. (defconstant $t_cons 4)
  46. (defconstant $t_sfloat 5)
  47. (defconstant $t_lfun 6)
  48. (defconstant $t_imm 7)
  49.  
  50. ; Non-cons cells have a header long-word for the garbage collector.
  51. (defconstant $vector-header #x1ff)
  52. (defconstant $symbol-header #x8ff)
  53.  
  54.  
  55. ; Vectors are a longword of block header, 1 byte of subtype, 3 bytes of length (in bytes)
  56. ; then the contents.
  57. ;
  58. ;  -------------------
  59. ; | 00 | 00 | 01 | FF |
  60. ; |-------------------|
  61. ; | ST |    Length    |
  62. ; |-------------------|
  63. ; |     Contents      |
  64. ; |         .         |
  65. ; |         .         |
  66. ; |         .         |
  67. ;  -------------------
  68.  
  69. ; Array subtypes. Multiply by two to get the MCL subtype
  70. ;(defconstant $v_packed_sstr 0)          ; used in image loader/dumper
  71. (defconstant $v_bignum 1)
  72. (defconstant $v_macptr 2)
  73. (defconstant $v_badptr 3)
  74. (defconstant $v_nlfunv 4)               ; Lisp FUNction vector
  75. ;subtype 5 unused
  76. ;subtype 6 unused
  77. (defconstant $v_min_arr 7)
  78. (defconstant $v_ubytev 7)    ;unsigned byte vector
  79. (defconstant $v_uwordv 8)    ;unsigned word vector
  80. (defconstant $v_floatv 9)    ;float vector
  81. (defconstant $v_slongv 10)   ;Signed long vector
  82. (defconstant $v_ulongv 11)   ;Unsigned long vector
  83. (defconstant $v_bitv 12)     ;Bit vector
  84. (defconstant $v_sbytev 13)   ;Signed byte vector
  85. (defconstant $v_swordv 14)   ;Signed word vector
  86. (defconstant $v_sstr 15)     ;simple string
  87. (defconstant $v_genv 16)     ;simple general vector
  88. (defconstant $v_arrayh 17)   ;complex array header
  89. (defconstant $v_struct 18)   ;structure
  90. (defconstant $v_mark 19)     ;buffer mark
  91. (defconstant $v_pkg 20)
  92. ;subtype 21 unused
  93. (defconstant $v_istruct 22)
  94. (defconstant $v_ratio 23)
  95. (defconstant $v_complex 24)
  96. (defconstant $v_instance 25) ;clos instance
  97. ; subtypes 26, 27, 28 unused.
  98. (defconstant $v_weakh 29)
  99. (defconstant $v_poolfreelist 30)
  100. (defconstant $v_nhash 31)
  101.  
  102. ; Types that exist only in the database
  103. (defconstant $v_area 32)                ; area descriptor
  104. (defconstant $v_segment 33)             ; area segment
  105. (defconstant $v_random-bits 34)         ; used for vectors of random bits, e.g. resources
  106. (defconstant $v_dbheader 35)            ; database header
  107. (defconstant $v_segment-headers 36)     ; Segment headers page.
  108. (defconstant $v_btree 37)               ; a BTREE
  109. (defconstant $v_btree-node 38)          ; one node of a BTREE's tree.
  110. (defconstant $v_class 39)               ; class
  111.  
  112. (defconstant $v_link (- $t_vector))
  113. (defconstant $V_SUBTYPE 3)
  114. (defconstant $V_DATA 7)
  115. (defconstant $V_LOG 3)
  116. (defconstant $vector-header-size 8)
  117.  
  118. (defconstant $vnodebit 5)               ; set for arrays containing pointers
  119. (defconstant $vnode (lsh 1 $vnodebit))
  120.  
  121. ; NIL is tagged as a cons with and address of 0
  122. (defconstant $pheap-nil $t_cons)
  123.  
  124. (defmacro def-indices (&body indices)
  125.   (let ((index 0)
  126.         res)
  127.     (dolist (spec indices)
  128.       (labels ((f (spec)
  129.                  (etypecase spec
  130.                    (symbol (push `(defconstant ,spec ,index) res))
  131.                    (list (dolist (sub-spec spec)
  132.                            (f sub-spec))))))
  133.         (declare (dynamic-extent f))
  134.         (f spec)
  135.         (incf index)))
  136.     `(progn ,@(nreverse res))))
  137.  
  138. ; Symbols are not regular vectors.
  139. (defconstant $sym_header -2)            ; $symbol-header
  140. (defconstant $sym_pname 2)
  141. (defconstant $sym_package 6)
  142. (defconstant $sym_values 10)            ; place for (value function . plist)
  143. (defconstant $symbol-size 16)
  144.  
  145. ; Packages do not support inheritance.
  146. ; maybe they should.
  147. (def-indices
  148.   $pkg.names
  149.   $pkg.btree
  150.   $pkg-length)
  151.  
  152. ; Weak lists. Subtype $v_weakh
  153. (def-indices
  154.   $population.gclink
  155.   $population.type
  156.   $population.data
  157.   $population-size)
  158.  
  159. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  160. ;;
  161. ;; A PHEAP file starts with a single vector containing
  162. ;; the root objects and the file-wide information.
  163. ;;
  164. (defconstant $block-overhead 8)         ; commit-lsn + segment-ptr
  165. (defconstant $block-commit-lsn 0)
  166. (defconstant $block-segment-ptr 4)
  167.  
  168. (defconstant $root-vector (+ $block-overhead $t_vector))
  169.  
  170. (def-indices
  171.   $pheap.version                        ; version number
  172.   $pheap.free-page                      ; free pointer in pages
  173.   $pheap.root                           ; root object
  174.   $pheap.default-consing-area           ; a pointer to an area descriptor
  175.   $pheap.class-hash                     ; class hash table
  176.   $pheap.page-size                      ; size of a page in bytes
  177.   $pheap.btree-free-list                ; head of linked list of btree nodes
  178.   $pheap.package-btree                  ; string->package table
  179.   $pheap.page-write-count               ; pages written since open
  180.   $pheap-free9
  181.   $pheap-free10
  182.   $pheap-free11
  183.   $pheap-free12
  184.   $pheap-free13
  185.   $pheap-free14
  186.   $pheap-free15
  187.   $pheap-header-size
  188.   )
  189.  
  190. ; A segment headers page header. Subtype is $v_segment-headers
  191. ; The header in the first page of headers for an area
  192. ; contains the $area.xxx information as well.
  193. (def-indices
  194.   $segment-headers.area                 ; my area
  195.   $segment-headers.link                 ; next segment headers page
  196.   $area.flags                           ; fixnum
  197.   $area.segment-size                    ; default size for segments
  198.   $area.last-headers                    ; last segment headers page
  199.   $area.free-count                      ; number of headers left in $area.last-headers
  200.   $area.free-ptr                        ; cons pointing at current header
  201.   $area-descriptor-size
  202.   )
  203.  
  204. (defconstant $segment-headers-size $area.flags)
  205.  
  206. ; A segment header page entry
  207. ; Pointers to these are typed as conses
  208. (defconstant $segment-header_free -4)   ; pointer to free space. Tagged as a cons
  209. (defconstant $segment-header_freebytes 0)       ; number of bytes left
  210. (defconstant $segment-header_free-link 4)       ; header entry with free space
  211. (defconstant $segment-header_segment 8)         ; beginning of the segment
  212. (defconstant $segment-header-entry-bytes (* 4 4))       ; must be a multiple of 8
  213.  
  214. ; The header of a segment. Subtype is $v_segment
  215. ; This vector contains all other types of objects
  216. (def-indices
  217.   $segment.area                         ; my area
  218.   $segment.header                       ; my header entry
  219.   $segment-header-size
  220.   )
  221.  
  222. ; Complex array headers
  223. ; Copied from lispequ.
  224. (def-indices
  225.   $arh.fixnum
  226.   $arh.offs
  227.   $arh.vect
  228.   ($arh.vlen $arh.dims)
  229.   $arh.fill)
  230.  
  231. ;byte offsets in arh.fixnum slot.
  232. (defconstant $arh_rank4 0)        ;4*rank
  233. (defconstant $arh_type 2)        ;vector subtype
  234. (defconstant $arh_bits 3)        ;Flags
  235.  
  236. (defconstant $arh_one_dim 4)        ;arh.rank4 value of one-dim arrays
  237.  
  238. ;Bits in $arh_bits.
  239. (defconstant $arh_adjp_bit 7)        ;adjustable-p
  240. (defconstant $arh_fill_bit 6)        ;fill-pointer-p
  241. (defconstant $arh_disp_bit 5)        ;displaced to another array header -p
  242. (defconstant $arh_simple_bit 4)        ;not adjustable, no fill-pointer and
  243.                     ; not user-visibly displaced -p
  244.  
  245. (defmacro dc-%arrayh-bits (disk-cache pointer)
  246.   `(the fixnum
  247.         (read-8-bits ,disk-cache
  248.                      (+ ,pointer $v_data (* 4 $arh.fixnum) $arh_bits))))
  249.  
  250. (defmacro dc-%arrayh-type (disk-cache pointer)
  251.   `(the fixnum
  252.         (read-8-bits ,disk-cache
  253.                      (+ ,pointer $v_data (* 4 $arh.fixnum) $arh_type))))
  254.  
  255. (defmacro dc-%arrayh-rank4 (disk-cache pointer)
  256.   `(the fixnum
  257.         (read-unsigned-word
  258.          ,disk-cache
  259.          (+ ,pointer $v_data (* 4 $arh.fixnum) $arh_rank4))))
  260.  
  261. (defmacro arh.fixnum_type-bytespec ()
  262.   (byte 8 5))
  263.  
  264. (defmacro arh.fixnum_type (fixnum)
  265.   `(ldb (arh.fixnum_type-bytespec) ,fixnum))
  266.  
  267. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  268. ;;;
  269. ;;; btree vector - subtype $v_btree
  270. ;;;
  271. (def-indices
  272.   $btree.root                           ; the root node
  273.   $btree.count                          ; number of leaf entries
  274.   $btree.depth                          ; 0 means only the root exists
  275.   $btree.nodes                          ; total number of nodes
  276.   $btree.first-leaf                     ; first leaf node. A constant
  277.   $btree.type                           ; type bits
  278.   $btree-size                           ; length of a $v_btree vector
  279.   )
  280.  
  281. ;; Btree type bits
  282. (defconstant $btree-type_eqhash-bit 0)          ; EQ hash table
  283. (defconstant $btree-type_weak-bit 1)    ; weak hash table
  284. (defconstant $btree-type_weak-value-bit 2)      ; weak on value, not key
  285.  
  286. ; Btree type values
  287. (defconstant $btree-type_normal 0)      ; normal string->value btree
  288. (defconstant $btree-type_eqhash (ash 1 $btree-type_eqhash-bit))
  289. (defconstant $btree-type_eqhash-weak-key
  290.   (+ $btree-type_eqhash (ash 1 $btree-type_weak-bit)))
  291. (defconstant $btree-type_eqhash-weak-value
  292.   (+ $btree-type_eqhash-weak-key (ash 1 $btree-type_weak-value-bit)))
  293.  
  294. ;; Persistent CLOS equates
  295.  
  296. ; subtype $v_instance
  297. (def-indices
  298.   $instance.wrapper                     ; class wrapper
  299.   $instance.slots                       ; slots vector
  300.   $instance-size)
  301.  
  302. ; A wrapper is a regular general vector
  303. (def-indices
  304.   $wrapper.class
  305.   $wrapper.slots                        ; vector of slot names
  306.   $wrapper-size)
  307.  
  308. ; subtype $v_class
  309. (def-indices
  310.   $class.name
  311.   $class.own-wrapper
  312.   $class-size)
  313.  
  314. (defmacro %unbound-marker ()
  315.   (ccl::%unbound-marker-8))
  316.  
  317. (provide :woodequ)
  318.